#ifndef __MYCHART_H__
#define __MYCHART_H__

#include "facecat/stdafx.h"
#include "Security.h"
#include "facecat/FCClientService.h"
#include "facecat/FCSplitLayoutDiv.h"
#include "FCChartEx.h"
class CycleButton;

/*
 * 图表件
 */
class MyChart: public FCSplitLayoutDiv, public FCListenerMessageCallBack, public FCInvokeEventCallBack{
public:
    MyChart();
    FCChartEx *m_chart;
    String m_code;
    int m_subscription;
    int m_cycle;
    int m_requestID;
    int m_lastChangeID;
    double m_lastPixel;
    ArrayList<CycleButton*> m_cycleButtons;
    ClientTickDataCache m_clientTickDataCache;
    ArrayList<SecurityData> m_securityDatasCache;
    void onSearchCode(String code);
public:
    /*
     * 回调方法
     *@param sender
     *@param message
     *@param invoke
     */
    void callListenerMessageEvent(Object sender, FCMessage *message, Object invoke);
    /*
     * 绑定历史数据
     *@param chart
     *@param historyDatas
     */
    void bindHistoryDatas(String code, int cycle, ArrayList<SecurityData>, bool refresh);
    /*
     * 添加均价线
     */
    void addAvgLine();
    /*
     * 添加组件方法
     */
    virtual void onAdd();
    /*
     * 查询代码
     *@param code
     *@param cycle 
     */
    void searchSecurity(String code, int cycle);
    virtual void update();
    /*
     * 设置属性
     *@param name
     *@param value
     */
    virtual void setAttribute(const String& name, const String& value);
    /*
     * 点击事件
     *@param evenName
     *@param sender
     *@param touchInfo
     *@param invoke
     */
    virtual void callTouchEvent(String eventName, Object sender,FCTouchInfo touchInfo, Object invoke);
    /*
     * 图表的黑色风格
     *@param chart
     */
    void chartToBlack(FCChart *chart);
    /*
     * 白色风格
     *@param chart
     */
    void chartToWhite(FCChart *chart);
    /*
     * 插入数据
     *@param chart 证券视图
     *@param dataSource 数据源
     *@param fields 字段
     *@param securityData 证券数据
     */
    int insertData(FCChart *chart, SecurityData *securityData);
    int m_clearRequestID;
    /*
     * 接收最新数据
     *@param latestData
     */
    void newData(SecurityLatestData *latestData, int requestID, bool refresh);
    void callInvokeEvent(String eventName, Object sender, Object args,Object invoke);
    void clearDatas();
};

/*
 * 周期按钮
 */
class CycleButton: public FCButton{
    
public:
    CycleButton();
    int m_cycle;
    MyChart *m_chart;
    virtual Long getPaintingTextColor();
    virtual void onPaintForeground(FCPaint *paint, const FCRect& clipRect);
};

#endif
